package org.example.volunteerend.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.volunteerend.entity.ProjectCategory;

@Mapper
public interface UserInterestCategoryMapper {
    
    /**
     * 获取用户感兴趣的分类列表
     */
    @Select("SELECT c.category_id, c.category_name, c.description, c.icon_url " +
            "FROM user_interest_categories uc " +
            "JOIN project_categories c ON uc.category_id = c.category_id " +
            "WHERE uc.user_id = #{userId}")
    List<ProjectCategory> getUserInterestCategories(@Param("userId") Integer userId);
    
    /**
     * 添加用户感兴趣的分类
     */
    @Insert("INSERT INTO user_interest_categories (user_id, category_id) VALUES (#{userId}, #{categoryId})")
    void addUserInterestCategory(@Param("userId") Integer userId, @Param("categoryId") Integer categoryId);
    
    /**
     * 检查用户是否对某个分类感兴趣
     */
    @Select("SELECT COUNT(*) FROM user_interest_categories WHERE user_id = #{userId} AND category_id = #{categoryId}")
    int checkUserInterestCategory(@Param("userId") Integer userId, @Param("categoryId") Integer categoryId);
    
    /**
     * 删除用户的所有兴趣分类
     */
    @Delete("DELETE FROM user_interest_categories WHERE user_id = #{userId}")
    void deleteUserInterestCategories(@Param("userId") Integer userId);
} 